# Maintainer: Clayton Craft <clayton@craftyguy.net>
# Co-Maintainer: Caleb Connolly <caleb@postmarketos.org>
pkgname=linux-postmarketos-qcom-laptop
pkgver=6.13
pkgrel=0
# Commit from branch @ https://github.com/jhovold/linux/tree/wip/x1e80100-$pkgver
_commit="0df45c8ef99147234f541062be775907b28ad768"
pkgdesc="Generic kernel for Qualcomm laptops"
arch="aarch64"
_carch="arm64"
_flavor="postmarketos-qcom-laptop"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip
	!check
	!tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-uefi
	pmb:kconfigcheck-virt
"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	findutils
	flex
	git
	openssl-dev
	perl
	python3
	zstd
"
replaces="linux-lenovo-21bx"

# Source
_repository="linux"
source="
	$pkgname-$_commit.tar.gz::https://github.com/jhovold/$_repository/archive/$_commit.tar.gz
	misc.config
	pmos.config
	0001-partially-revert-arm64-dts-qcom-sc8280xp-enable-GICv.patch
"
builddir="$srcdir/linux-$_commit"
_outdir="out"
_defconfig="johan_defconfig"

prepare() {
	default_prepare
	cp "$srcdir/pmos.config" "$builddir"/arch/"$_carch"/configs/
	cp "$srcdir/misc.config" "$builddir"/arch/"$_carch"/configs/

	# Generate .config
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor" \
		"$_defconfig" pmos.config misc.config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	install -Dm644 "$builddir/arch/$_carch/boot/vmlinuz.efi" \
			"$pkgdir/boot/linux.efi"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs

	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
b49abf68751eb34eb83a716f03695b118eb42beaac44dc2116349475a5783d759879fedc052fe0b9d845bc4549211b302b68598c86526a75867abf35e2437fe3  linux-postmarketos-qcom-laptop-0df45c8ef99147234f541062be775907b28ad768.tar.gz
980eefd8aaee78897cd41d039eecc11e23b8d7cc87b41c869f1e2b83cd9b5dac9813d7bd1a0e7c466303c795f234871080686921b9672983604551903004cb68  misc.config
c761143bbdb621a1698068b2369473786638dc4b1c34c9c92466b053a7d4a5ed4e69dbdf731b57b40a1eb99b0f92a6ceaed1cc7302ab6584ef9a779cb225538e  pmos.config
8bd939e56b3bd6e9b268fe48f3cbaf9ea48eb41cf96edc5b6facb9e0c30553c336baba57efd2f549d7d6a56e8687a4fce211b59d2bc1cf16fd92780f38406d65  0001-partially-revert-arm64-dts-qcom-sc8280xp-enable-GICv.patch
"
